<?php
class PFTCore777{
	
	public $inside = null;
	
	public function __construct(){
		
	}
	
	
	public static function Member_Sale_Products(){
		
	}
	

	
	// 获取指定产品价格及库存
	// $mode   获取类型 0 分销价 1 零售价 2 都获取
	// $lower  指定日期获取不到价格是否获取最低价
	public static function Dynamic_Price_And_Storage($inside, $account, $pid, $aid, $today, $mode=2, $storage=1, $lower=true){
		
		$clsResult = array('js'=>array('p'=>-1,'s'=>-1), 'ls'=>array('p'=>-1,'s'=>-1));// 返回的价格数组
		if($mode==0 || $mode==2){// 获取结算价
			$resxml = $inside->Dynamic_Price_And_Storage($account, $pid, $today, 1, 0, 1, $aid);
			if($resxml==105  && $lower) $resxml = $inside->Dynamic_Price_And_Storage($account, $pid, $today, 2, 0, $storage, $aid);
			if($resxml==105 || $resxml==1065) return $clsResult;
			$simxml = simplexml_load_string($resxml);
			$clsResult['js']['p'] = (string)$simxml->Rec->UUsprice/100;
			if($storage==1) $clsResult['js']['s'] = (string)$simxml->Rec->UUstorage;
		}
		
		if($mode==1 || $mode==2 ){// 获取零售价
			$resxml = $inside->Dynamic_Price_And_Storage($account, $pid, $today, 1, 1, 1, $aid);
			if($resxml==105 && $lower) $resxml = $inside->Dynamic_Price_And_Storage($account, $pid, $today, 2, 1, $storage, $aid);
			if($resxml==105 || $resxml==1065) return $clsResult;
			$simxml = simplexml_load_string($resxml);
			$clsResult['ls']['p'] = (string)$simxml->Rec->UUsprice/100;
			if($storage==1) $clsResult['ls']['s'] = (string)$simxml->Rec->UUstorage;
		}
		return $clsResult;
	}
	
	// 获取会员的供应商列表
	public static function Suppliers($memberID){
		$suppliers = array();
		$sql = "select r.id,r.parent_id,m.dname from pft_member_relationship r left join pft_member m on r.parent_id=m.id where r.son_id=$memberID and r.ship_type=0 and r.status=0 and parent_id<>$memberID and m.status=0 and m.id>1";
		$GLOBALS['le']->query($sql);
		while($row=$GLOBALS['le']->fetch_assoc()) $suppliers[$row['parent_id']] = $row['dname'];
		return $suppliers;
	}
	
	// 获取会员的分销商列表
	public static function Distributors($memberID){
		$distributors = array();
		$sql = "select r.id,r.son_id,m.dname from pft_member_relationship r left join pft_member m on r.son_id=m.id where r.parent_id=$memberID and r.ship_type=0 and r.status=0 and son_id<>$memberID and m.status<3 and m.id>1";
		$GLOBALS['le']->query($sql);
		while($row=$GLOBALS['le']->fetch_assoc()) $distributors[$row['son_id']] = $row['dname'];
		return $distributors;
	}
	
	
	// 获取会员的供应商列表
	public static function Member_Suppliers($memberID){
		$suppliers = array();
		$sql = "select r.id,r.parent_id,m.dname from pft_member_relationship r left join pft_member m on r.parent_id=m.id where r.son_id=$memberID and r.ship_type=0 and r.status=0 and parent_id<>$memberID";
		$GLOBALS['le']->query($sql);
		while($row=$GLOBALS['le']->fetch_assoc()) $suppliers[$row['parent_id']] = $row['dname'];
		return $suppliers;
	}
	
	
	// 获取会员的分销商列表
	public static function Member_Distributors($memberID){
		$distributors = array();
		$sql = "select r.id,r.son_id,m.dname from pft_member_relationship r left join pft_member m on r.son_id=m.id where r.parent_id=$memberID and r.ship_type=0 and r.status=0 and son_id<>$memberID";
		$GLOBALS['le']->query($sql);
		while($row=$GLOBALS['le']->fetch_assoc()) $distributors[$row['son_id']] = $row['dname'];
		return $distributors;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}